<?php

class model_theme extends model
{

	public $uri = 'http://www.mrbone.org/webservices';
	public $uri_theme = 'http://www.mrbone.org/webservices/theme';


	public function get_theme_list()
	{
		$db = bone::get_db();
		return $db->get_objs( 'SELECT * FROM `bone_theme`' );
	}


	public function make_default($theme_id)
	{
		$db = bone::get_db();
		$db->execute( 'UPDATE `bone_theme` SET `is_default`=0 WHERE `is_default`=1' );

		$table = bone::get_table('template', APP_DIR);
		$table->load($theme_id);
		$table->is_default = 1;
		$table->save();

		$config = bone::get_config('theme');
		$config->name = $table->theme;
		$model = bone::get_model('config', APP_DIR);
		$model->save($config, 'theme');
	}

	public function delete($theme_id)
	{
		$table = bone::get_table('theme', APP_DIR);
		$table->load($theme_id);

		if($table->is_default)
		{
			$this->error = '正在使用的主题不能删除';
			return false;
		}

		if(!$table->theme)
		{
			$this->error = '不存在的主题';
			return false;
		}

		$theme_path = BONE_ROOT.DS.'themes'.DS.$table->theme;

		$fso = bone::get('fso');
		$fso->delete_folder($theme_path);

		$table->delete($theme_id);

		return true;
	}

}
?>